package edu.temple.mobile.adapters;

import java.util.List;

import edu.temple.mobile.R;
import edu.temple.mobile.objectClasses.TrolleyRoutes;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TrolleyRoutesAdapter extends ArrayAdapter<TrolleyRoutes> {

	int resource;
	String response;
	Context context;
	//Initialize adapter
	public TrolleyRoutesAdapter(Context context, int resource, List<TrolleyRoutes> items) {
		super(context, resource, items);
		this.resource=resource;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LinearLayout alertView;
		//Get the current alert object
		TrolleyRoutes al = getItem(position);

		//Inflate the view
		if(convertView==null)
		{
			alertView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, alertView, true);
		}
		else
		{
			alertView = (LinearLayout) convertView;
		}
		//Get the text boxes from the listitem.xml file
		TextView routeShortName =(TextView)alertView.findViewById(R.id.txtRouteShortName);
		TextView routeLongName =(TextView)alertView.findViewById(R.id.txtRouteLongName);
		
		/*Variables to change the color of the text for route short name text*/
		//Variable to store the hex color code 
		String color = ""; 
		
		//Variable to store the integer color code that will be used by the Android method parseColor
		int c = 0;

		//Assign the appropriate data from our alert object above
		if(al.route_long_name.equals("Yeadon-Darby To Center  City       ") && al.route_id == 9839){			
			color = "#006600";
			c = Color.parseColor(color);
			routeShortName.setText("13");
			routeShortName.setTextColor(c);
			routeLongName.setText(al.route_long_name + " (Limited Service)");
		}else{
		color = "#006600";
		c = Color.parseColor(color);
		routeShortName.setText(Integer.toString(al.route_short_name));
		routeShortName.setTextColor(c);
		routeLongName.setText(al.route_long_name);
		}
		return alertView;
	}

}
